﻿
@{
    ViewBag.Title = "结果录入";
}

<div class="row col-md-12 ml-0 pre-scrollable" style="min-height:95vh;">
    <div class="row col-md-12 tab-content" style="padding-left: 0;padding-right: 0px;right: -15px;min-height: 4vh;">
        <ul class="nav col-md-12" style="padding-right: 0;margin-bottom: 1px;">
            <li id="li-tabEqList" class="col-md-1 font-rfs" style="padding-top:5px; border-bottom: 1px solid #a8bfde;">
                <strong class="font-rfs" style="margin-right: 2rem;padding-top: 5px;">结果录入</strong>
            </li>
            <li id="li-tabSingle" class="tab tabButton col-md-1 tab-first-active font-rfs" style="text-align:center;padding-left: 1px;padding-right: 1px;" data-active="true">
                <a id="a-tabSingle" href="#Single" data-toggle="tab" class="text-decoration-none" style="display: inline-block;width:100%;padding-top: 5px;">单样处理</a>
            </li>
            <li id="li-tabMulti" class="tab tabButton col-md-1 tab-other-noactive font-rfs" style="text-align:center;padding-left: 1px;padding-right: 1px;" data-active="false">
                <a id="a-tabMulti" href="#Multi" data-toggle="tab" class="text-decoration-none" style="display: inline-block;width:100%;padding-top: 5px;">批量处理</a>
            </li>
            <li class="col-md-9 tab-Notactive" style="text-align: center;"><a href="" data-toggle="tab"></a></li>
        </ul>
    </div>
    <div class="row col-md-12 tab-content tab-body" style="padding-right: 0px;right: -15px;padding-left: 0px;top: -2px;min-height: 90vh;">
        <div class="col-md-12 ml-0 mr-0 tab-pane active" id="Single" style="padding-left: 0px;padding-right: 0px;">
            <div class="row col-md-12 ml-0" style="min-height:5vh;padding-left: 2px;">
                <select id="Runtime-ResultEntry-SelectBatch" class="form-control font-rfs border-radius-noradius noRightBorder custom-headtoolbar-select" style="width:10% !important;"></select>
                <select id="Runtime-ResultEntry-SelectType" class="form-control font-rfs border-radius-noradius noRightBorder custom-headtoolbar-select" style="width:10% !important;">
                    <option></option>
                    <option>样品编号</option>
                    <option>名称</option>
                    <option>类型</option>
                    <option>分类</option>
                </select>
                <input id="Runtime-ResultEntry-Name" class="btn btn-rfs border-radius-noradius" style="border: 1px solid rgba(0,0,0,.15);height: calc(1.5em + .75rem + 1px) !important;width:10% !important;" onchange="SearchByType(this)" />
                <button id="Runtime-ResultEntry-ImportData" class="btn btn-rfs"><i class="bi-database-fill-add"></i> 导入数据</button>
                <button id="Runtime-ResultEntry-Abandon" class="btn btn-rfs"><i class="bi-x-circle" style="color:red"></i> 废弃</button>
            </div>
            <div class="row col-md-12 ml-0" style="min-height:84vh;padding-right: 0px;">
                <div class="row col-md-12" style="padding-right:0px;padding-left: 0px;">
                    <div class="table-responsive-sm shadow p-0 bg-white rounded col-md-12 pre-scrollable" style="min-height:36vh;">
                        <table id="Runtime-ResultEntry-Table" class="table table-striped table-bordered table-sm table-hover">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>样品ID</th>
                                    <th>样品编号</th>
                                    <th>批次号</th>
                                    <th>名称</th>
                                    <th>样品描述</th>
                                    <th>类型</th>
                                    <th>分类</th>
                                    <th>附件</th>
                                    <th>指派人</th>
                                    <th>指派组</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                    </div>
                </div>
                <div class="row col-md-12" style="margin-top: 7px; padding-right:0px;padding-left: 0px;min-height: 49vh;">
                    <div class="row col-md-12 tab-content" style="padding-left: 0;padding-right: 0px;right: -15px;height: 3vh;">
                        <ul class="nav col-md-12" style="padding-right: 0;margin-bottom: 1px;">
                            <li id="li-tabAnalyte" class="tabButton col-md-1 tab-first-active font-rfs" style="text-align:center;padding-left: 1px;padding-right: 1px;" data-active="true">
                                <a id="a-tabAnalyte" href="#tabAnalyte" data-toggle="tab" class="text-decoration-none" style="display: inline-block;width:100%;">结果录入</a>
                            </li>
                            <li class="col-md-11 tab-Notactive" style="text-align: center;"><a href="" data-toggle="tab"></a></li>
                        </ul>
                    </div>
                    <div class="row col-md-12 tab-content" style="padding-right: 0px;right: -15px;padding-left: 0px;top: -2px;">
                        <div class="col-md-12 ml-0 mr-0 tab-pane active" id="tabAnalyte" style="padding-left: 0px;padding-right: 0px;">
                            <div class="row col-md-12" style="min-height:4vh;">
                                <button id="Runtime-ResultEntry-Initial" class="btn btn-rfs"><i class="bi-arrow-repeat" style="color:#007bff;"></i> 初始化</button>
                            </div>
                            <div class="table-responsive-sm p-0 bg-white rounded col-md-12 pre-scrollable" style="min-height:40vh">
                                <table id="Runtime-ResultEntry-TabAnalyts" class="table table-striped table-bordered table-sm table-hover">
                                    <thead>
                                        <tr>
                                            <th>ID</th>
                                            <th>样品ID</th>
                                            <th>样品编号</th>
                                            <th>测试名称</th>
                                            <th>代码</th>
                                            <th>名称</th>
                                            <th>修约</th>
                                            <th>-3σ</th>
                                            <th>-2σ</th>
                                            <th>Std</th>
                                            <th>+2σ</th>
                                            <th>+3σ</th>
                                            <th>原始结果</th>
                                            <th>单位</th>
                                            <th>最终结果</th>
                                            <th>单位</th>
                                            <th>结论</th>
                                            <th>重测</th>
                                            <th>检测序号</th>
                                            <th>测试序号</th>
                                            <th>状态</th>
                                        </tr>
                                    </thead>
                                    <tbody></tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-12 ml-0 mr-0 tab-pane" id="Multi" style="padding-left: 0px;padding-right: 0px;">
            <div class="row col-md-12 ml-0" style="min-height:5vh;padding-left: 2px;">
                <select id="Runtime-ResultEntry-SelectMultiBatch" class="form-control font-rfs border-radius-noradius noRightBorder custom-headtoolbar-select" style="width:10% !important;"></select>
                <select id="Runtime-ResultEntry-SelectMultiAnalyt" class="form-control font-rfs border-radius-noradius custom-headtoolbar-select" style="width:8% !important;"></select>
                <select id="Runtime-ResultEntry-SelectEqId" class="form-control font-rfs border-radius-noradius custom-headtoolbar-select" style="width:8% !important;"></select>
                <button id="Runtime-ResultEntry-DefaultResults" class="btn btn-rfs"><i class="bi-arrow-down-circle" style="color:#007bff;"></i> 默认结果</button>
            </div>
            <div class="col-md-12 ml-0 mr-0 tab-pane active" id="tabAnalyte" style="padding-left: 0px;padding-right: 0px;">
                <div class="table-responsive-sm p-0 bg-white rounded col-md-12 pre-scrollable" style="min-height:85vh">
                    <table id="Runtime-ResultEntry-TabMulti" class="table table-striped table-bordered table-sm table-hover">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th></th>
                                <th>样品ID</th>
                                <th>样品编号</th>
                                <th>测试名称</th>
                                <th>测试次数</th>
                                <th>分析项</th>
                                <th>结果</th>
                                <th>设备类型</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="Runtime-ResultEntry-Modal" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p id="Runtime-ResultEntry-Modal-Title" class="pt-3 pl-3 font-rfs"></p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <div id="Runtime-ResultEntry-Modal-Embed"></div>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="Runtime-ResultEntry-DoAbandon" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p class="pt-3 pl-3 font-rfs">废弃样品</p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <p class="font-rfs">请输入废弃样品的原因：</p>
                <p><textarea id="modal-Suggestion" class="font-rfs" rows=2 style="width:100%;"></textarea></p>
            </div>
            <div class="modal-Delete-footer">
                <button id="modal-DoAbandon" class="btn btn-outline-primary border-radius-noradius noLeftBorder noRightBorder font-rfs" style="width:50%; height:fit-content">确定</button>
                <button id="cancleDoAbandon" data-dismiss="modal" class="btn btn-outline-primary border-radius-noradius noRightBorder font-rfs" style="width:50%; height:fit-content">取消</button>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="Runtime-ResultEntry-IiniModal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p class="pt-3 pl-3 font-rfs">初始化分析项</p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <p class="font-rfs">初始化分析项操作不可恢复，是否继续？</p>
            </div>
            <div class="modal-Delete-footer">
                <button id="Runtime-ResultEntry-IiniModal-confirm" class="btn btn-outline-primary border-radius-noradius noLeftBorder noRightBorder font-rfs" style="width:50%; height:fit-content">确定</button>
                <button id="Runtime-ResultEntry-IiniModal-cancel" data-dismiss="modal" class="btn btn-outline-primary border-radius-noradius noRightBorder font-rfs" style="width:50%; height:fit-content">取消</button>
            </div>
        </div>
    </div>
</div>

@section Scripts {
    <script src="~/js/jspdf.js" type="module"></script>
    <script>
        var sampleid = "";
        $(document).ready(function () {
            LoadBatchByResult('Runtime-ResultEntry-SelectBatch');
            LoadBatchByResult('Runtime-ResultEntry-SelectMultiBatch');
        });

        $("#Runtime-ResultEntry-SelectBatch").change(function () {
            var batchid = $("#Runtime-ResultEntry-SelectBatch").find("option:selected").text();
            LoadSamplesByBatchId(batchid);
            $('#Runtime-ResultEntry-TabAnalyts').bootstrapTable('destroy');
        });

        $("#Runtime-ResultEntry-SelectMultiBatch").change(function () {
            var batchid = $("#Runtime-ResultEntry-SelectMultiBatch").find("option:selected").text();
            $.post("/Sample/GetResultAnalyteList", {
                batchid: batchid
            }, function (data) {
                $('#Runtime-ResultEntry-SelectMultiAnalyt').empty(); // 清除现有项
                for (var i = 0; i < data.length; i++) {
                    $('#Runtime-ResultEntry-SelectMultiAnalyt').append(new Option(data[i]));
                }
                $('#Runtime-ResultEntry-SelectMultiAnalyt').val("");
            });
        });

        function SetMulOriginal(value, row, index) {
            var text = value == null ? '' : value;
            var select = "<select class='table-cell-select' onchange='MultiOriginal(this)'>";
            var input, cell;

            if (row.alternativeResults != null) {
                var alarry = row.alternativeResults.split(',');
                select = select + "<option></option>";
                for (var i = 0; i < alarry.length; i++) {
                    select = select + "<option>" + alarry[i] + "</option>";
                }
                select = select + "</select>";
                input = "<input class='table-cell-input' " + "onkeydown='UpdateMulFinal(this, event)' onclick='stopPropagation(this, event)' value='" + text + "' data-resultId='" + row.id + "' style='text-align: center;' />";
                cell = "<div class='input-group position-relative'>" + select + "<div class='col-10 input-group position-absolute float-left' style='padding-left: 0px;'>" + input + "</div></div>"
                return cell;
            } else {
                return "<input class='table-cell-input' " + "onkeydown='UpdateMulFinal(this, event)' value='" + text + "' data-resultId='" + row.id + "' style='text-align: center;' />";
            }
        }

        function UpdateMulFinal(obj, event) {
            if (event.keyCode === 13) {
                var result = $(obj).val();
                var id = $(obj).attr('data-resultId');
                var index = parseInt($(obj).parent().parent().parent().parent().attr('data-index'));
                if (index !== index) {
                    index = parseInt($(obj).parent().parent().attr('data-index'));
                }

                $.post("ManualResult", {
                    Id: id,
                    Original: result,
                    EqId: $('#Runtime-ResultEntry-SelectEqId').find("option:selected").text()
                }, function (datas) {
                    if (datas.indexOf("异常") > 0) {
                        alert(datas);
                        return;
                    }
                    $("#Runtime-ResultEntry-TabMulti").find("tbody").find("tr").eq(index).removeClass('changeblueColor');
                    $("#Runtime-ResultEntry-TabMulti").find("tbody").find("tr").eq(index + 1).addClass("changeblueColor");
                    $("#Runtime-ResultEntry-TabMulti").find("tbody").find("tr").eq(index + 1).find("input").focus();
                });
            }
        }

        function stopPropagation(obj, event) {
            event.stopPropagation();
        }

        $("#Runtime-ResultEntry-SelectMultiAnalyt").change(function () {
            $('#Runtime-ResultEntry-TabMulti').bootstrapTable('destroy');
            var columns = [{ field: "id", visible: false }, { field: "selectItem", width: "5%", align: "center", checkbox: true },
            { field: "sampleId", width: "10%" }, { field: "sampleNumber", width: "10%" }, { field: "testName" },
            { field: "testTimes" }, { field: "analytesCode" }, { field: "original", formatter: SetMulOriginal }, { field: "eqType" }];

            $('#Runtime-ResultEntry-TabMulti').bootstrapTable({
                method: 'post',
                url: "/Sample/GetTobeTestResultList",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        batchid: $("#Runtime-ResultEntry-SelectMultiBatch").find("option:selected").text(),
                        analytesCode: $("#Runtime-ResultEntry-SelectMultiAnalyt").find("option:selected").text(),
                        limit: params.limit, // 每页显示多少条记录
                        offset: params.offset, // 偏移量
                    };
                    return data;
                },
                queryParamsType: "limit", // 服务器端分页，这个参数必需是“limit”
                sidePagination: "server", // 服务器端分页，这个参数必需设置
                pagination: true,  // 显示分页条,设为true，启用了分页功能
                pageNumber: 1,
                pageSize: 30,   // 默认页大小
                pageList: [30, 50, 100, 150],  // 控制每页数目
                locale: "zh-CN",
                columns: columns,

                selectItemName: "selectItem", // 指定选择行ID
                clickToSelect: true, // 相应单击，自动选中此行
                checkboxHeader: true, // 标题行显示全选按钮

                uniqueId: "id",          // 设置主键
                locale: "zh-CN",
                columns: columns,
                onClickRow: function (row, $element, field) {
                    $("#Runtime-ResultEntry-TabMulti").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                    var id = row.id;
                    LoadEquipmentByType('Runtime-ResultEntry-SelectEqId', row.eqType);
                },
                silent: true,
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#Runtime-ResultEntry-TabMulti').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        });

        function SetStatus(value, row, index) {
            var strHtml = "-";
            if (value == "Done") {
                strHtml = "<i class='bi bi-check-circle-fill'></i>";
            }
            if (value == "OOG") {
                strHtml = "<i class='bi bi-exclamation-circle-fill'></i>";
            }
            if (value == "OOS") {
                strHtml = "<i class='bi bi-x-circle-fill'></i>";
            }
            return strHtml;
        }

        function setAttachment(value, row, index) {
            var strHtml = "<button class='table-cell-button btn-rfs' data-Method-Id=" + row.id + " onclick='TableCellButton(this)'><i class='bi-tools' title='附件管理'></i></button>";
            return strHtml;
        }

        function TableCellButton(obj) {
            $("#Runtime-ResultEntry-Modal-Title").text("样品附件管理");

            $("#Runtime-ResultEntry-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });

            $.post("/Common/ManageFile", {
                Domain: "Sample",
                DomainId: $(obj).parent().parent().attr('data-uniqueid'),
                ModalID: "Runtime-ResultEntry-Modal"
            }, function (datas) {
                $("#Runtime-ResultEntry-Modal-Embed").html(datas);
            });
            event.stopPropagation();
        }

        function LoadSamplesByBatchId(batchid) {
            $('#Runtime-ResultEntry-Table').bootstrapTable('destroy');
            var columns = [{ field: "id", visible: false }, { field: "sampleId", width: "10%" }, { field: "sampleNumber" }, { field: "batchId" }, { field: "name" },
            { field: "description" }, { field: "classification" }, { field: "genricClass" }, { field: "SopFiles", width: "5%", formatter: setAttachment },
            { field: "assignPersonName" }, { field: "assignGroupName" }];

            $('#Runtime-ResultEntry-Table').bootstrapTable({
                method: 'post',
                url: "GetRestltSamplesByBatchId",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        limit: params.limit, // 每页显示多少条记录
                        offset: params.offset, // 偏移量
                        BatchId: batchid
                    };
                    return data;
                },
                queryParamsType: "limit", // 服务器端分页，这个参数必需是“limit”
                dataField: "rows",

                uniqueId: "id",          // 设置主键
                sidePagination: "server", // 服务器端分页，这个参数必需设置
                pagination: true,  // 显示分页条,设为true，启用了分页功能
                pageNumber: 1,
                pageSize: 10,   // 默认页大小
                pageList: [5, 10, 15, 20],  // 控制每页数目
                locale: "zh-CN",
                columns: columns,
                onClickRow: function (row, $element, field) {
                    $("#Runtime-ResultEntry-Table").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                    sampleid = row.id;
                    LoadSingleResult(row.id);
                },
                silent: true,
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#Runtime-ResultEntry-Table').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        function ReleaseOnClick(obj) {
            var st = $(obj).prop("checked");
            var rowid = $(obj).attr("data-rowid");

            $.post("UpdateSampleLoginIsRelease", {
                SampleLoginId: rowid,
                IsRelease: st
            }, function (data) {
                if (data.indexOf("成功") < 0) {
                    alert(data);
                }
            });
        }

        function SearchByType(obj) {
            var type = $("#Runtime-ResultEntry-SelectType").find("option:selected").text();
            if (type.length == 0)
                alert("请先选择需要查询的类别！");

            LoadSamples(type, $(obj).val());
        }

        function LoadSamples(type, value) {
            $('#Runtime-ResultEntry-Table').bootstrapTable('destroy');
            var columns = [{ field: "id", visible: false }, { field: "sampleId", width: "10%" }, { field: "batchId" }, { field: "name" },
            { field: "description" }, { field: "classification" }, { field: "genricClass" }, { field: "SopFiles", width: "5%", formatter: setAttachment },
            { field: "assignPersonName" }, { field: "assignGroupName" }, { field: "alternativeResults", visible: false }];

            $('#Runtime-ResultEntry-Table').bootstrapTable({
                method: 'post',
                url: "GetRestltSamples",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        limit: params.limit, // 每页显示多少条记录
                        offset: params.offset, // 偏移量
                        Type: type,
                        value: value
                    };
                    return data;
                },
                queryParamsType: "limit", // 服务器端分页，这个参数必需是“limit”
                dataField: "rows",

                uniqueId: "id",          // 设置主键
                sidePagination: "server", // 服务器端分页，这个参数必需设置
                pagination: true,  // 显示分页条,设为true，启用了分页功能
                pageNumber: 1,
                pageSize: 10,   // 默认页大小
                pageList: [5, 10, 15, 20],  // 控制每页数目
                locale: "zh-CN",
                columns: columns,
                onClickRow: function (row, $element, field) {
                    $("#Runtime-ResultEntry-Table").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                    LoadSingleResult(row.id);
                },
                silent: true,
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#Runtime-ResultEntry-Table').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        function SetStatus(value, row, index) {
            var strHtml = "-";
            if (value == "Done") {
                strHtml = "<i class='bi bi-check-circle-fill'></i>";
            }
            if (value == "OOG") {
                strHtml = "<i class='bi bi-exclamation-circle-fill'></i>";
            }
            if (value == "OOS") {
                strHtml = "<i class='bi bi-x-circle-fill'></i>";
            }
            return strHtml;
        }

        function SetOriginal(value, row, index) {
            var text = value == null ? '' : value;
            var select = "<select class='table-cell-select' onchange='SelectChange(this)'>";
            var input, cell, recordSheet="";
            
            if (row.methodId != "null") {
                //alert(row.methodId);
                recordSheet = " ondblclick = 'CallRecordSheet(this)'";
            }

            if (row.alternativeResults != null) {
                var alarry = row.alternativeResults.split(',');
                select = select + "<option></option>";
                for (var i = 0; i < alarry.length; i++) {
                    select = select + "<option>" + alarry[i] + "</option>";
                }
                select = select + "</select>";
                input = "<input class='table-cell-input' " + "onkeydown='UpdateFinal(this, event)'" + recordSheet + " value='" + text + "' data-resultId='" + row.id + "' style='text-align: center;' />";
                cell = "<div class='input-group position-relative'>" + select + "<div class='col-10 input-group position-absolute float-left' style='padding-left: 0px;'>" + input + "</div></div>"
                return cell;
            } else {
                return "<input class='table-cell-input' " + "onkeydown='UpdateFinal(this, event)'" + recordSheet + " value='" + text + "' data-resultId='" + row.id + "' style='text-align: center;' />";
            }
        }

        function CallRecordSheet(obj) {
            var id = $(obj).attr('data-resultId');
            $.post("CallRecordSheet", {
                ResultId: id
            }, function (datas) {
                newWindow = window.open();
                newWindow.jsPDF = window.jspdf.jsPDF;
                newWindow.document.write(datas);
            });
        }

        function SelectChange(obj) {
            var value = obj.value;
            $(obj).parent().find("input:first").val(value);
            obj.selectedIndex = 0;

            $.post("ManualResult", {
                Id: $(obj).parent().find("input:first").attr('data-resultId'),
                Original: value
            }, function (datas) {
                if (datas.indexOf("异常") > 0) {
                    alert(datas);
                    return;
                }
                for (var i = 0; i < datas.length; i++) {
                    var row = $('#Runtime-ResultEntry-TabAnalyts').bootstrapTable('getRowByUniqueId', datas[i].id); // 获得行数据
                    row.original = datas[i].original;
                    row.final = datas[i].final;
                    row.status = datas[i].status;
                    row.conclusion = datas[i].conclusion;
                    $('#Runtime-ResultEntry-TabAnalyts').bootstrapTable('updateByUniqueId', row);  // 更新行数据
                }
            });
        }

        function MultiOriginal(obj) {
            var value = obj.value;
            $(obj).parent().find("input:first").val(value);
            obj.selectedIndex = 0;

            $.post("ManualResult", {
                Id: $(obj).parent().find("input:first").attr('data-resultId'),
                Original: value
            }, function (datas) {
                if (datas.indexOf("异常") > 0) {
                    alert(datas);
                    return;
                }
                for (var i = 0; i < datas.length; i++) {
                    var row = $('#Runtime-ResultEntry-TabAnalyts').bootstrapTable('getRowByUniqueId', datas[i].id); // 获得行数据
                    row.original = datas[i].original;
                    row.final = datas[i].final;
                    row.status = datas[i].status;
                    row.conclusion = datas[i].conclusion;
                    $('#Runtime-ResultEntry-TabAnalyts').bootstrapTable('updateByUniqueId', row);  // 更新行数据
                }
            });
        }

        function UpdateFinal(obj,event) {
            if (event.keyCode === 13) {
                var result = $(obj).val();
                var id = $(obj).attr('data-resultId');
                var index = parseInt($(obj).parent().parent().parent().parent().attr('data-index'));
                if (index !== index) {
                    index = parseInt($(obj).parent().parent().attr('data-index'));
                }
                
                $.post("ManualResult", {
                    Id: id,
                    Original: result
                }, function (datas) {
                    if (datas.indexOf("异常") > 0) {
                        alert(datas);
                        return;
                    }
                    for (var i = 0; i < datas.length; i++) {
                        var row = $('#Runtime-ResultEntry-TabAnalyts').bootstrapTable('getRowByUniqueId', datas[i].id); // 获得行数据
                        row.original = datas[i].original;
                        row.final = datas[i].final;
                        row.status = datas[i].status;
                        row.conclusion = datas[i].conclusion;
                        $('#Runtime-ResultEntry-TabAnalyts').bootstrapTable('updateByUniqueId', row);  // 更新行数据
                        $("#Runtime-ResultEntry-TabAnalyts").find("tbody").find("tr").eq(index).removeClass('changeblueColor');
                        $("#Runtime-ResultEntry-TabAnalyts").find("tbody").find("tr").eq(index + 1).addClass("changeblueColor");
                        $("#Runtime-ResultEntry-TabAnalyts").find("tbody").find("tr").eq(index + 1).find("input").focus();
                    }
                });
            }
        }

        function LoadSingleResult(id) {
            $('#Runtime-ResultEntry-TabAnalyts').bootstrapTable('destroy');
            var columns = [{ field: "id", visible: false }, { field: "sampleId", width: "10%" }, { field: "sampleNumber" },
            { field: "testName" }, { field: "analytesCode" }, { field: "analytesName" }, { field: "roundingOff" }, { field: "lowA", width: "3%" },
            { field: "lowB", width: "3%" }, { field: "standardValue", width: "3%" }, { field: "highB", width: "3%" }, { field: "highA", width: "3%" },
            { field: "original", formatter: SetOriginal }, { field: "units", width: "3%" }, { field: "final", width: "5%" }, { field: "fUnits", width: "3%" },
            { field: "conclusion" },{ field: "retestNo", width: "5%" }, { field: "detectionTimes", width: "5%" }, { field: "testTimes", width: "5%" },
            { field: "status", width: "3%", align: "center", formatter: SetStatus }];

            $('#Runtime-ResultEntry-TabAnalyts').bootstrapTable({
                method: 'post',
                url: "GetSampleResults",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        Id: id
                    };
                    return data;
                },
                queryParamsType: "limit", // 服务器端分页，这个参数必需是“limit”
                dataField: "rows",

                uniqueId: "id",          // 设置主键
                locale: "zh-CN",
                columns: columns,
                onClickRow: function (row, $element, field) {
                    $("#Runtime-ResultEntry-TabAnalyts").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                },
                silent: true,
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#Runtime-ResultEntry-TabAnalyts').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        $("#Runtime-ResultEntry-Abandon").click(function () {
            if (sampleid == "") {
                return false;
            }

            $("#Runtime-ResultEntry-DoAbandon").modal({
                backdrop: 'static',
                keyboard: false
            });
        });

        $("#modal-DoAbandon").click(function () {
            var suggestion = $("#modal-Suggestion").val();
            suggestion = $.trim(suggestion);
            if (suggestion.length == 0) {
                alert("请输入废弃样品原因！");
            }

            $.post("DoAbandon", {
                SampleIds: sampleid,
                Suggestion: suggestion
            }, function (data) {
                sampleid == "";
                alert(data);
                $("#Runtime-ResultEntry-DoAbandon").modal('hide');
            });
        });

        $("#Runtime-ResultEntry-ImportData").click(function () {
            $("#Runtime-ResultEntry-Modal-Title").text("仪器数据导入");

            $("#Runtime-ResultEntry-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });

            $.post("/Common/AddUsageRecord", {
                ModalID: "Runtime-ResultEntry-Modal"
            }, function (datas) {
                $("#Runtime-ResultEntry-Modal-Embed").html(datas);
            });
        });

        $("#Runtime-ResultEntry-DefaultResults").click(function () {
            var ids = GetSelectItems('Runtime-ResultEntry-TabMulti');
            if (ids == null) {
                alert("没有选择任何样品！");
            }

            $.post("DefaultResults", {
                Ids: ids,
                EqId: $("#Runtime-ResultEntry-SelectEqId").find("option:selected").text()
            }, function (data) {
                alert(data);
            });
        });

        $("#Runtime-ResultEntry-Initial").click(function () {
            var id = GetSelectIdByColor('Runtime-ResultEntry-TabAnalyts');
            if (id.length == 0) {
                alert("请先选择需要初始化的分析项！");
                return;
            }

            $("#Runtime-ResultEntry-IiniModal").modal({
                backdrop: 'static',
                keyboard: false
            });
        });

        $("#Runtime-ResultEntry-IiniModal-confirm").click(function () {
            var rid = GetSelectIdByColor('Runtime-ResultEntry-TabAnalyts');
            $.post("InitializeAnalysis", {
                ResultId: rid
            }, function (data) {
                var row = $('#Runtime-ResultEntry-TabAnalyts').bootstrapTable('getRowByUniqueId', rid); // 获得行数据
                row.original = null;
                row.final = null;
                row.conclusion = null;
                row.status = null;
                $('#Runtime-ResultEntry-TabAnalyts').bootstrapTable('updateByUniqueId', rid, row);
                $("#Runtime-ResultEntry-IiniModal").modal('hide');
            });
        });

        $(".tab").hover(
            function () {
                if ($(this).attr("class").indexOf('tab-other-active') > 0) {
                    $(this).addClass('tab-enter-mouse');
                }
                if ($(this).attr("class").indexOf('tab-other-noactive') > 0) {
                    $(this).removeClass('tab-other-noactive');
                    $(this).addClass('tab-other-noactive-mouse');
                }
            },
            function () {
                $(this).removeClass('tab-enter-mouse');
                $(this).removeClass('tab-other-noactive-mouse');

                if ($(this).attr("data-active") == 'true') {
                    $(this).addClass('tab-other-active');
                }
                if ($(this).attr("data-active") == 'false') {
                    $(this).addClass('tab-other-noactive');
                }
            });

        $("#a-tabSingle").click(function () {
            if ($("#li-tabSingle").attr("class").indexOf('tab-first-noactive') > 0) {
                $("#li-tabSingle").removeClass('tab-first-noactive');
                $("#li-tabSingle").addClass('tab-first-active');
            }

            if ($("#li-tabMulti").attr("class").indexOf('tab-other-active') > 0) {
                $("#li-tabMulti").removeClass('tab-other-active');
                $("#li-tabMulti").addClass('tab-other-noactive');
            }

            $("#li-tabSingle").attr("data-active", true);
            $("#li-tabMulti").attr("data-active", false);
        });

        $("#a-tabMulti").click(function () {
            if ($("#li-tabSingle").attr("class").indexOf('tab-first-active') > 0) {
                $("#li-tabSingle").removeClass('tab-first-active');
                $("#li-tabSingle").addClass('tab-first-noactive');
            }

            if ($("#li-tabMulti").attr("class").indexOf('tab-other-active') > 0) {
                $("#li-tabMulti").removeClass('tab-other-active');
                $("#li-tabMulti").addClass('tab-other-noactive');
            }

            $("#li-tabSingle").attr("data-active", false);
            $("#li-tabMulti").attr("data-active", true);
        });

    </script>
}
